package com.handu.luna.core.domain.goods;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.handu.luna.core.domain.BaseRepository;
 
public interface BrandRepository extends JpaRepository<Brand,Long>, BaseRepository<Brand>,JpaSpecificationExecutor<Brand>{
	
	Page<Brand> findAll(Pageable pageable);

	@Query("from Brand b where b.name like CONCAT('%',:name,'%') order by displayOrder asc,id asc ")
	Page<Brand> findByNameLike(@Param("name") String name,Pageable pageable);
	
	@Query("from Brand b where b.name like CONCAT('%',:name,'%') and b.type = :type order by displayOrder asc,id asc ")
	Page<Brand> findByNameAndType(@Param("name") String name , @Param("type") Brand.BrandType type , Pageable pageable);
	
	@Query("from Brand b where b.type = :type order by displayOrder asc,id asc ")
	Page<Brand> findByType(@Param("type") Brand.BrandType type , Pageable pageable);
	
	@Query("from Brand b where type=0 order by displayOrder asc")
	List<Brand> findCommonBrands();
	
	/**
	 * 通用信息模块调用
	 * @author wangzailiang
	 * @param name
	 * @return
	 */
	List<Brand> findByNameLike(String name);
	
}
